package com.example.webdownloadserver.handle.upload.thread;


import com.dnkj.download.task.util.DateTool;
import com.example.webdownloadserver.base.TaskThreadAbastract;
import com.example.webdownloadserver.beans.UserExcel;
import com.example.webdownloadserver.dao.UserDao;
import com.example.webdownloadserver.vo.TaskCenter;
import com.example.webdownloadserver.vo.UserBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName UploadUserThread
 * @Description TODO
 * @Auth ying.xiao
 * @Date 2021/5/21
 * @Version 1.0.0
 */
@Slf4j
@Component
public class UploadUserThread extends TaskThreadAbastract<UserExcel> {

    @Autowired
    private UserDao userDao;

    @Override
    public void doing(List<UserExcel> datalist, TaskCenter taskCenter) throws ParseException {
        log.info("UploadUserThread deal size:{}",datalist.size());
        List<String> receipt = new ArrayList();
        for (int i = 0; i < datalist.size(); i++) {
            UserExcel userExcel = datalist.get(i);
            UserBean userBean = new UserBean();
            userBean.setId(userExcel.getId());
            userBean.setUserName(userExcel.getUserName());
            userBean.setPassword(userExcel.getPassword());
            userDao.saveAndFlush(userBean);
        }
        wirteFile(receipt,"user-receipt.txt",datalist.size(),taskCenter);
    }
}
